<?php
	require '../config/config.php';
	$ConfigSql="select * from config where id='1'";
	$ConfigInfo=mysqli_query($con,$ConfigSql);
	$ConnfigRs=mysqli_fetch_array($ConfigInfo);
	session_start();
	if(empty($_SESSION['member'])){
	    echo "<script>location='../../index.php';</script>";
	    exit;
	}
	if($_GET['ops']=="logout"){
	    $_SESSION['member']="";
	    session_destroy();
	    echo "<script>alert('您已退出登录！');location='../index.php';</script>";
	}
	if(!empty($_SESSION['member'])){
	    //$UserSql=mysqli_query($con,"select * from member while user='".$_SESSION['member']."'");
		//$UserInfo=mysqli_fetch_array($UserSql);
		$UserSql="SELECT * FROM `member` WHERE user='".$_SESSION['member']."'";
		$UserInfo=mysqli_query($con,$UserSql);
		@$UserRs=mysqli_fetch_array($UserInfo);
		//echo "<script>alert('".$UserInfo['type']."');</script>";
		if($UserRs['type']!="1" and $UserRs['type']!="2"){
		    echo "<script>location='../index.php';</script>";
		}else{
		    $ConfigSql="SELECT * FROM `config` WHERE id='1'";
		    $Config=mysqli_query($con,$ConfigSql);
		    @$ConfigRs=mysqli_fetch_array($Config);
		}
	}
	if(empty($_GET['id'])){
	    echo "<script>alert('系统异常！');location='../index.php';</script>";
	}else{
		$rs=mysqli_fetch_array(mysqli_query($con,"select * from feedback where id='".$_GET['id']."'"));
		if(empty($rs['id'])){
		    echo "<script>location='../index.php';</script>";
		}
	}
	if($_POST){
		$subject=$_POST['subject'];
		$more=$_POST['more'];
		$total_amount=$_POST['total_amount'];
		if(empty($subject) or empty($more) or empty($total_amount)){
			echo "<script>alert('请填写完整信息！');</script>";
		}else{
		    function getKey($len, $chars=null){
            	if (is_null($chars)){
            		$chars = "0123456789";
            	}  
            	mt_srand(10000000*(double)microtime());
            	for ($i = 0, $str = '', $lc = strlen($chars)-1; $i < $len; $i++){
            		$str .= $chars[mt_rand(0, $lc)];  
            	}
            	return $str;
            }
		    $orderNo = "HYSSACS".date('Ymd').time().getKey(22);
			mysqli_query($con,"INSERT INTO `orderRecord` (`id`, `user`, `bno`, `subject`, `more`, `total_amount`, `state`, `cdate`, `pdate`,`feedbackid`) VALUES ('','".$rs['adduser']."', '".$orderNo."', '".$subject."', '".$more."','".$total_amount."', '0', '".date("Y/m/d H:i:s")."', '', '".$_GET['id']."')");
    	    echo "<script>alert('已发起订单！');location='../index.php';</script>";
		}
	}
?>
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <title><?php echo $ConnfigRs['name'];?>-我的订单</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="../css/head.css"/>
  <link rel="stylesheet" href="../layui/css/layui.css">

<link rel="stylesheet" href="../css/global.css">

<script src="../layui/layui.js"></script>
</head>
<body >

<div class="dvhead">
	<div class="dvlogo"><a href="index.php">你问我答</a></div>
	<div class="dvreg">
		<?php
		    if(empty($_SESSION['member'])){
                echo "已有账号，立即&nbsp;<a href='login.php'>登录</a>";
            }else{
                echo "欢迎您，".$_SESSION['member']." &nbsp;&nbsp;<a href='?ops=logout'> 退出</a>";
            }
		?>
	</div>
</div>

<div class="main layui-clear">
  <div class="fly-panel" pad20>
    <div class="layui-form layui-form-pane">
        <br />&nbsp;&nbsp;&nbsp;<a href="../index.php">首页</a> / 我的订单<br /><br />
        <form method="post">
            <table class="news-edit">
    			<tr>
    				<th>订单名称：</th>
    				<td><input type="text" name="subject" placeholder="请输入订单名称" class="layui-input"></td>
    			</tr>
    			<tr>
    				<th>订单内容：</th>
    				<td><input type="text" name="more" placeholder="请输入订单内容" class="layui-input"></td>
    			</tr>
    			<tr>
    				<th>订单金额：</th>
    				<td><input type="text" name="total_amount" placeholder="请输入订单金额" class="layui-input"></td>
    			</tr>
    			<tr>
    				<th></th>
    				<td><input type="submit" value="确认发起"  class="layui-btn"/></td>
    			</tr>
    		</table>
		</form>
    </div>
  </div>
</div>

 <script type="text/javascript" charset="utf-8" src="js/kindeditor.js"></script>
  <script type="text/javascript">
    KE.show({
        id : 'content',
		resizeMode : 1,
        cssPath : './index.css',
        items : [
        'fontname', 'fontsize', 'textcolor', 'bgcolor', 'bold', 'italic', 'underline',
        'removeformat', 'justifyleft', 'justifycenter', 'justifyright', 'insertorderedlist',
        'insertunorderedlist', 'emoticons', 'image', 'link']
    });
  </script>
<script>

layui.cache.page = '';
layui.cache.user = {
  username: '游客'
  ,uid: -1
  ,avatar: '../res/images/avatar/00.jpg'
  ,experience: 83
  ,sex: '男'
};
layui.config({
  version: "2.0.0"
  ,base: '../res/mods/'
}).extend({
  fly: 'index'
}).use('fly');
</script>
</body>
</html>